<?php
/**
 * Created by IntelliJ IDEA.
 * User: TinND
 * Date: 4/3/14
 * Time: 1:57 PM
 */
include '../connection.php';

$data = json_decode(file_get_contents("php://input"));
if (isset($data->api)) {
    mysql_query("SET NAMES 'utf8'");

    switch ($data->api) {
        case 1222:
            /* grab the posts from the db */
            $query = "INSERT INTO Product(name, description, type, price, status, created) " .
                "VALUES('$data->name',  '$data->description', '$data->type',  '$data->price',  '$data->status',  '$data->created')";
            $result = mysql_query($query, $link) or die('Errant query:  ' . $query);

            header('Content-type: application/json');
            $answer = array('success' => true, 'id' => mysql_insert_id());
            echo json_encode($answer);
            break;

        case "bar":
            echo "i is bar";
            break;
        case "cake":
            echo "i is cake";
            break;
    }
} else {
    echo json_encode(array('success' => false, 'message' => $data->api));
}